﻿using UnityEngine;
using System.Collections;
using FrameWork;
using UnityEngine.UI;

public class TestOne : BaseUI{

    //抽象函数必须要基类里赋值
    public override EnumUIType GetUIType()
    {
        return EnumUIType.TestOne;
    }

    private Button btn;
	// Use this for initialization
	void Start () {

    //    btn = transform.Find("Panel/Button").GetComponent<Button>();
     //   btn.onClick.AddListener(OnClickedBtn);

   //     EventTriggerListener.Get(transform.Find("Panel/Button").gameObject).SetEventHandle(EnumTouchEventType.OnClick, Close);
//         EventTriggerListener listenter = EventTriggerListener.Get(transform.Find("Panel/Button").gameObject);
//         listenter.SetEventHandle(EnumTouchEventType.OnClick, Close,1,"1234");
        StartCoroutine(AutoUpdateGold());
	}

    private IEnumerator AutoUpdateGold()
    {
        int gold = 0;
        while (true)
        {
            gold++;
            yield return new WaitForSeconds(2f);
            Message message = new Message("AutoUpdateGold",this);
            message["gold"] = gold;
            message.Send();
        }
    }

    protected override void OnAwake()
    {
        MessageCenter.Intance.AddListener("AutoUpdateGold", UpdateGold);
        base.OnAwake();
    }

    protected override void OnRelease()
    {
        MessageCenter.Intance.RemoveListener("AutoUpdateGold", UpdateGold);
        base.OnRelease();
    }

    private void UpdateGold(Message message)
    {
        int gold = (int)message["gold"];
        Debug.LogError("=================" + gold.ToString());
    }
	
	// Update is called once per frame
	void Update () {
	
	}

    private void OnClickedBtn()
    {
          UIManager.Intance.OpenUI(EnumUIType.TestTwo);
          UIManager.Intance.CloseUI(EnumUIType.TestOne);
       // UIManager.Intance.OpenUICloseOthers(EnumUIType.TestTwo);
//        // GameObject go = Instantiate<GameObject>(Resources.Load<GameObject>("Prefabs/TestTwo"));
//         GameObject go = Instantiate(Resources.Load("Prefabs/TestTwo")) as GameObject;
//         TestTwo tt = go.GetComponent<TestTwo>();
//         if ( null == tt)
//         {
//            /* tt =*/ go.AddComponent<TestTwo>();
//         }
       
    }

    private void Close(EventTriggerListener _listener, object _args, params object[] _params)
    {
        int i = (int)_params[0];
        string s = (string)_params[1];
        Debug.LogError("=====================" + i);
        Debug.LogError("!!!!!!!!!!!!!!!!!!!!!!"+s);

        UIManager.Intance.OpenUICloseOthers(EnumUIType.TestTwo);
    }

}
